import { defineStore } from 'pinia';

export const useAuthStore = defineStore('auth', {
  state: () => ({
    tokenValue: localStorage.getItem('tokenValue') || null,
    tokenName: localStorage.getItem('tokenName') || null
  }),
  actions: {
    login(tokenValue) {
      this.tokenValue = tokenValue;
      localStorage.setItem('tokenValue', tokenValue);
    },
    logout() {
      this.tokenValue = null;
      localStorage.removeItem('tokenValue');
    },
    setTokenName(tokenName) {
      this.tokenName = tokenName;
      localStorage.setItem('tokenName', tokenName);
    }
  },
  getters: {
    isLogin: (state) => !!state.tokenValue
  }
});